#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=60,maxt=1e6+10,maxm=5*1e5;
typedef int LL;
LL tree[maxm][27];
char str[maxn],res[maxt];
LL fail[maxm],flag[maxm],pc=0;
inline void ins(const char* s){
     LL n=strlen(s);LL cur=0;
     for(int i=0;i<n;i++){
        char v=s[i]-'a';
        if(!tree[cur][v]) tree[cur][v]=++pc;
        cur=tree[cur][v];
     }
     flag[cur]++;
}
inline void getfail(){
     queue<LL>que;
     fail[0]=0;
     for(int i=0;i<26;i++){
         LL u=tree[0][i];
         if(u) {que.push(u);fail[u]=0;}
     }
     while(!que.empty()){
          LL r=que.front();que.pop();
          for(int c=0;c<26;c++){
              LL u=tree[r][c];
              if(!u) continue;
              que.push(u);
              LL v=fail[r];
              while(v&&!tree[v][c]) v=fail[v];
              fail[u]=tree[v][c];
          }
     }
}
inline LL fd(const char* p){
    LL j=0;LL ans=0;LL n=strlen(p);
    for(int i=0;i<n;i++){
        LL c=p[i]-'a';
        while(j&&!tree[j][c]) j=fail[j];
        j=tree[j][c];
        LL temp=j;
        while(temp!=0&&flag[temp]!=-1){
            ans+=flag[temp];
            flag[temp]=-1;
            temp=fail[temp];
        }
    }
    return ans;
}
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    LL t;cin>>t;
    while(t--){
        LL n;cin>>n;
        for(int i=0;i<n;i++){
            cin>>str;
            ins(str);
        }
        getfail();
        cin>>res;
        cout<<fd(res)<<"\n";
        pc=0;
        memset(flag,0,sizeof(flag));
        memset(tree,0,sizeof(tree));
    }
   	return 0;
}
